/*
 * @Author: panghu chenjh@datamargin.com
 * @Date: 2024-03-26 16:23:44
 * @LastEditors: panghu chenjh@datamargin.com
 * @LastEditTime: 2024-03-26 17:53:23
 * @FilePath: \vue3-vite-mall-admin-system\src\utils\request.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import axios from 'axios'

const instance = axios.create({
  baseURL: '/api',
  timeout: 5000
})

instance.interceptors.request.use(config => {
  const token = sessionStorage.getItem('token')
  if (token) {
    config['headers']['token'] = token
  }
  return config
})

instance.interceptors.response.use(response => {
  return response.data
}, err => {
  return err.response.data
})

export default instance